(function ($) {

    var fn = {
        parse: function(arr){
            console.log(arr);
            var _arr = [];
            $.each(arr, function (i, json) {
                _arr.push(json.y);
            });
            return _arr;
        },
        chart4Leakage: function (opts) {
            var _container = opts.chartContainer && opts.chartContainer.find('.chart-leakage')[0],
                _data = opts.data && opts.data.leakage_pre_task;

            if (_data) {
                _data = fn.parse(_data);
            }
            
            var option = {
                xAxis: {
                    type: 'category',
                    data: ['0-2', '2-4', '4-6', '6-8', '8-10', '10以上']
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    data: _data,
                    type: 'bar'
                }]
            };
            echarts.init(_container).setOption(option);

        },
        chart4LeakageArea: function (opts) {
            var _container = opts.chartContainer && opts.chartContainer.find('.chart-leakage-area')[0],
                _data = opts.data && opts.data.leakage_area_pre_task;

            if (_data) {
                _data = fn.parse(_data);
            }

            var option = {
                xAxis: {
                    type: 'category',
                    data: ['0-1', '1-2', '2-3', '3-4', '4-5', '5以上']
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    data: _data,
                    type: 'bar'
                }]
            };
            echarts.init(_container).setOption(option);
        }
    };

    $.chart = {
        show: function (opts) {
           fn.chart4Leakage(opts);
           fn.chart4LeakageArea(opts);
        }
    }

})(jQuery);
